package com.cdsz.boot.system;

import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
import com.cdsz.boot.common.annotation.MapperScanner;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.util.oConvertUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.util.StopWatch;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.InetAddress;
import java.net.UnknownHostException;

@Slf4j
@SpringBootApplication(
        scanBasePackages = {"org.jeecg", "com.cdsz"},
        exclude = {
            SecurityAutoConfiguration.class,
            DataSourceAutoConfiguration.class,
            DruidDataSourceAutoConfigure.class,
            ManagementWebSecurityAutoConfiguration.class
        })
@MapperScanner(basePackages = {"org.jeecg.**.mapper", "com.cdsz.boot.**.mapper"})
public class CdszBootSystemApplication {

    public static void main(String[] args) throws UnknownHostException {
        StopWatch stopwatch = new StopWatch();
        stopwatch.start();
        ConfigurableApplicationContext application = SpringApplication.run(CdszBootSystemApplication.class, args);
        stopwatch.stop();
        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = oConvertUtils.getString(env.getProperty("server.servlet.context-path"));
        String appName = oConvertUtils.getString(env.getProperty("spring.application.name"));
        BigDecimal seconds = BigDecimal.valueOf(stopwatch.getTotalTimeSeconds()).setScale(2, RoundingMode.HALF_UP);
        log.info("\n----------------------------------------------------------\n\t" +
                "Application " + appName + " is running! 耗时: " + seconds + "s \n\t" +
                "Local: \t\thttp://localhost:" + port + path + "/\n\t" +
                "External: \thttp://" + ip + ":" + port + path + "/\n\t" +
                "Swagger: \thttp://" + ip + ":" + port + path + "/doc.html\n" +
                "----------------------------------------------------------");
    }

}
